Allow runner params
authorIngvar Stepanyan <me@rreverser.com>
Fri, 12 May 2017 22:07:42 +0000 (23:07 +0100)
committerIngvar Stepanyan <me@rreverser.com>
Fri, 12 May 2017 22:14:11 +0000 (23:14 +0100)
src/cargo/ops/cargo_rustc/compilation.rs
src/cargo/util/config.rs
tests/tool-paths.rs

index 594f3cb195c7a65dab9edfb4e7ba3d8edbd66d72..be3e16a04375539e5ccf006c0952925f9049fe57 100644 (file)
@@ -54,7 +54,7 @@ pub struct Compilation<'cfg> {
 
     config: &'cfg Config,
 
-    target_runner: LazyCell<Option<PathBuf>>,
+    target_runner: LazyCell<Option<(PathBuf, Vec<String>)>>,
 }
 
 impl<'cfg> Compilation<'cfg> {
@@ -94,18 +94,19 @@ impl<'cfg> Compilation<'cfg> {
         self.fill_env(process(cmd), pkg, true)
     }
 
-    fn target_runner(&self) -> CargoResult<&Option<PathBuf>> {
+    fn target_runner(&self) -> CargoResult<&Option<(PathBuf, Vec<String>)>> {
         self.target_runner.get_or_try_init(|| {
             let key = format!("target.{}.runner", self.target);
-            Ok(self.config.get_path(&key)?.map(|v| v.val))
+            Ok(self.config.get_path_and_args(&key)?.map(|v| v.val))
         })
     }
 
     /// See `process`.
     pub fn target_process<T: AsRef<OsStr>>(&self, cmd: T, pkg: &Package)
                                            -> CargoResult<ProcessBuilder> {
-        let builder = if let &Some(ref runner) = self.target_runner()? {
+        let builder = if let &Some((ref runner, ref args)) = self.target_runner()? {
             let mut builder = process(runner);
+            builder.args(args);
             builder.arg(cmd);
             builder
         } else {
index aa27fa0436c504d415f8e5c7016bdc2e295bb6da..f16110d249887efce4fd83b13826cde9a8fdbac3 100644 (file)
@@ -215,25 +215,40 @@ impl Config {
         }
     }
 
+    fn string_to_path(&self, value: String, definition: &Definition) -> PathBuf {
+        let is_path = value.contains('/') ||
+                      (cfg!(windows) && value.contains('\\'));
+        if is_path {
+            definition.root(self).join(value)
+        } else {
+            // A pathless name
+            PathBuf::from(value)
+        }
+    }
+
     pub fn get_path(&self, key: &str) -> CargoResult<Option<Value<PathBuf>>> {
         if let Some(val) = self.get_string(key)? {
-            let is_path = val.val.contains('/') ||
-                          (cfg!(windows) && val.val.contains('\\'));
-            let path = if is_path {
-                val.definition.root(self).join(val.val)
-            } else {
-                // A pathless name
-                PathBuf::from(val.val)
-            };
             Ok(Some(Value {
-                val: path,
-                definition: val.definition,
+                val: self.string_to_path(val.val, &val.definition),
+                definition: val.definition
             }))
         } else {
             Ok(None)
         }
     }
 
+    pub fn get_path_and_args(&self, key: &str) -> CargoResult<Option<Value<(PathBuf, Vec<String>)>>> {
+        if let Some(mut val) = self.get_list_or_split_string(key)? {
+            if !val.val.is_empty() {
+                return Ok(Some(Value {
+                    val: (self.string_to_path(val.val.remove(0), &val.definition), val.val),
+                    definition: val.definition
+                }));
+            }
+        }
+        Ok(None)
+    }
+
     pub fn get_list(&self, key: &str)
                     -> CargoResult<Option<Value<Vec<(String, PathBuf)>>>> {
         match self.get(key)? {
index 641ccba9a74c0a4f360ddc5497bbd6584fc119af..ef1a183d956f1bfb56027b6b1e1dc52cf11781b1 100644 (file)
@@ -140,7 +140,7 @@ fn custom_runner() {
         .file("benches/bench.rs", "")
         .file(".cargo/config", &format!(r#"
             [target.{}]
-            runner = "nonexistent-runner"
+            runner = "nonexistent-runner -r"
         "#, target));
 
     foo.build();
@@ -149,7 +149,7 @@ fn custom_runner() {
                 execs().with_stderr_contains(&format!("\
 [COMPILING] foo v0.0.1 ({url})
 [FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
-[RUNNING] `nonexistent-runner target[/]debug[/]foo[EXE] --param`
+[RUNNING] `nonexistent-runner -r target[/]debug[/]foo[EXE] --param`
 ", url = foo.url())));
 
     assert_that(foo.cargo("test").args(&["--test", "test", "--verbose", "--", "--param"]),
@@ -157,7 +157,7 @@ fn custom_runner() {
 [COMPILING] foo v0.0.1 ({url})
 [RUNNING] `rustc [..]`
 [FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
-[RUNNING] `nonexistent-runner [..][/]target[/]debug[/]deps[/]test-[..][EXE] --param`
+[RUNNING] `nonexistent-runner -r [..][/]target[/]debug[/]deps[/]test-[..][EXE] --param`
 ", url = foo.url())));
 
     assert_that(foo.cargo("bench").args(&["--bench", "bench", "--verbose", "--", "--param"]),
@@ -166,6 +166,6 @@ fn custom_runner() {
 [RUNNING] `rustc [..]`
 [RUNNING] `rustc [..]`
 [FINISHED] release [optimized] target(s) in [..]
-[RUNNING] `nonexistent-runner [..][/]target[/]release[/]deps[/]bench-[..][EXE] --param --bench`
+[RUNNING] `nonexistent-runner -r [..][/]target[/]release[/]deps[/]bench-[..][EXE] --param --bench`
 ", url = foo.url())));
 }